/*
 * Created on 29/06/2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package br.ufmg.dees.insane.ui.rich.learn.learn_view.model_solution_view;

import java.awt.BorderLayout;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JToolBar;
import javax.swing.text.Position;

import br.ufmg.dees.insane.model.disc.fem.FemModel;
import br.ufmg.dees.insane.ui.rich.learn.learn_controller.GridModelSolutionController;
import br.ufmg.dees.insane.ui.rich.learn.learn_controller.ModelSolutionController;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.CmdButton;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.CmdMenu;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.DrawingArea;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.IView;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnInterface;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnView;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.LearnViewState;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.Command;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.SelectCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.model_solution_view.command.GetSolutionCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.model_solution_view.command.Help6Command;

/**
 * @author Francisca
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ModelSolutionView extends LearnView {  
	
	//  No da arvore: ModelSolution
	private Command getSolutionCmd = new GetSolutionCommand(parent);
	private Command help6Cmd = new Help6Command(parent);
	
	//	No ModelSolution
    private CmdMenu itemGetSolution = new CmdMenu("Solution", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Solve16.gif")));
    private CmdMenu itemHelp6 = new CmdMenu("Help", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Help16.gif")));

    
    //No ModelSolution
    private CmdButton getSolution = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Solve16.gif")));
    private CmdButton help6 = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Help16.gif")));
   
    private JMenu menuModelSolution = new JMenu("Model Solution");
    protected JToolBar modelSolutionToolBar = new JToolBar();
    
	public ModelSolutionView(LearnInterface parent, FemModel m){
	    super(parent,m);
		super.setViewState(new LearnViewState());
		super.setDrawingArea(new DrawingArea((IView)this));
		super.setController(new ModelSolutionController(this));
		
		String gAnlType = m.getGlobalAnalysisModel().getType();
		
		if (!(gAnlType.equals("Grid"))) {
			super.setController(new ModelSolutionController(this));
		} else {
			super.setController(new GridModelSolutionController(this));
		}
		
		//Setting menu ModelSolution
		menuModelSolution.add(itemGetSolution);
		itemGetSolution.setCommand(getSolutionCmd);
		itemGetSolution.setEnabled(false);
		itemGetSolution.setMnemonic(KeyEvent.VK_C);
		itemGetSolution.addActionListener(parent);
            
		menuModelSolution.add(itemHelp6);
        itemHelp6.setCommand(help6Cmd);
        itemHelp6.setEnabled(false);
        itemHelp6.setMnemonic(KeyEvent.VK_H);
        itemHelp6.addActionListener(parent);
        
        modelSolutionToolBar.add(getSolution);
        getSolution.setToolTipText("Solution");
        getSolution.addActionListener(parent);
        getSolution.setCommand(getSolutionCmd);
        
        modelSolutionToolBar.add(help6);
		help6.setToolTipText("Help");
		help6.addActionListener(parent);
		help6.setCommand(help6Cmd);
        
	}
	
	public void init(){
	    super.init();
			parent.getMenuPanel().removeAll();
			parent.getMenuPanel().add(menuFile);
			itemSave.setEnabled(true);
			itemSaveAs.setEnabled(true);
			itemClose.setEnabled(true);
			itemPrint.setEnabled(true);
			menuExport.setEnabled(true);
			menuImport.setEnabled(true);
			parent.getMenuPanel().add(menuEdit);
			parent.getMenuPanel().add(menuView);
			parent.getMenuPanel().add(menuModelSolution);
			menuModelSolution.setEnabled(true);
			itemGetSolution.setEnabled(true);
			itemHelp6.setEnabled(true);
			parent.getMenuPanel().add(menuSettings);
			parent.getMenuPanel().add(menuHelp);
	        
			parent.getToolPanel().removeAll();
			parent.getToolPanel().add(fileToolBar);
			save.setEnabled(true);
			saveAs.setEnabled(true);
			print.setEnabled(true);
			delete.setEnabled(false);
			parent.getToolPanel().add(editToolBar);
			parent.getToolPanel().add(zoomToolBar);
			parent.getToolPanel().add(modelSolutionToolBar);
			getSolution.setEnabled(true);
			help6.setEnabled(true);
							
	        parent.getConsolePanel().setVisible(true);
			
			grid.setEnabled(true);
			snap.setEnabled(true);
			
			this.getDrawingArea().setRepainting(false);
			this.getDrawingArea().repaint();
	        
			parent.getConsoleHandler().setToCommandMode();
			parent.getConsoleHandler().setKeybCommand(null);
			
			this.setStateButtons();
			
			parent.getTree().setEnabled(true);
			parent.getTree().setSelectionPath(parent.getTree().getNextMatch("Model Solution", 0, Position.Bias.Forward));
			
			this.getController().compose();

			parent.getDrawPanel().removeAll();
			parent.getDrawPanel().add(this.getDrawingArea(), BorderLayout.CENTER);
			this.getDrawingArea().removeAllCommands();
			this.getDrawingArea().setClickedCommand(new SelectCommand(parent));
			this.getDrawingArea().setCursor();
			parent.getDrawPanel().repaint();
			parent.getDrawPanel().updateUI();
			
			parent.getJMenuBar().updateUI();
			parent.repaint();
	    }   

	public  JFrame getInterface(){
    	return parent;
    }
    
	public void setInterface(JFrame par){
    	this.parent = (LearnInterface)par;
    }

    public void setCoord(String x, String y){
    	this.parent.setCoord(x, y);
    }
    
    public void setMessage(String m){
    	this.parent.setMessage(m);
    }

}
